<template>
  <div>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48" >
            <a-col :md="8" :sm="24">
              <a-form-item label="支付单号">
                <a-input v-model="queryParam.id" placeholder="请输入支付单号"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="订单编号">
                <a-input v-model="queryParam.order_id " placeholder="请输入订单编号"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md=" 8 || 24" :sm="24">
              <a-form-item>
                <a-button type="primary" @click="queryTable">查询</a-button>
              </a-form-item>
            </a-col>
            <a-col :md=" 8 || 24" :sm="24">
              <a-form-item label="支付状态">
                <a-select v-model="queryParam.pay_state" placeholder="请选择支付状态" default-value="0">
                  <a-select-option value="0">全部</a-select-option>
                  <a-select-option value="10">待付款</a-select-option>
                  <a-select-option value="20">支付成功</a-select-option>
                  <a-select-option value="30">支付中</a-select-option>
                  <a-select-option value="40">支付失败</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <a-table :columns="columns" :dataSource="dataList" :pagination="false" rowKey="id">
        <a slot="name" slot-scope="text" href="javascript:">{{ text }}</a>
        <div slot="pay" slot-scope="text" >
          <a-tag color="blue">{{ text | payStatusFilter }}</a-tag>
        </div>
      </a-table>
      <my-pagination
        :total="pagination.totalCount"
        :pageSize="pagination.pageSize"
        :current="pagination.pageNo"
        @onChange="onChangePage"
        @onShowSizeChange="onShowSizeChangePage"
      ></my-pagination>
    </a-card>
  </div>
</template>

<script>
import MyPagination from '../../components/Autism/myPagination'
import { queryPayOrder } from '@/api/orderPay'

const columns = [
  {
    title: '支付单号',
    dataIndex: 'pay_no',
    key: 'pay_no'
  }, {
    title: '支付金额',
    dataIndex: 'amount',
    key: 'amount'
  },
  {
    title: '订单编号',
    dataIndex: 'order_id',
    key: 'order_id'
  }, {
    title: '支付状态',
    dataIndex: 'pay_state',
    key: 'pay_state',
    slots: { title: 'pay' },
    scopedSlots: { customRender: 'pay' }
  }, {
    title: '支付时间',
    key: 'pay_date_time',
    dataIndex: 'pay_date_time'
  }]
export default {
  name: 'OrderPay',
  components: {
    MyPagination
  },
  data: function () {
    return {
      pagination: {
        pageNo: 1,
        pageSize: 10,
        totalCount: 0
      },
      currentTab: 0,
      queryParam: {},
      columns,
      dataList: []
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    // 分页获取列表
    getList (isSearch) {
      let param = {
        page_index: this.pagination.pageNo,
        page_size: this.pagination.pageSize
      }

      if (isSearch) {
        param = Object.assign(this.pagination, this.queryParam)
      }
      queryPayOrder(param)
        .then((res) => {
          console.log(res)
          this.dataList = res.collection
          this.pagination.pageNo = res.page_index
          this.pagination.pageSize = res.page_size
          this.pagination.totalCount = res.total_count
        })
        .catch((err) => {
          console.log(err)
        })
    },
    queryTable () {
      console.log(this.queryParam)
      this.getList(true)
    },
    onChangePage (pageNo, pageSize) {
      this.pagination.pageNo = pageNo
      // 重新请求数据
      this.getList()
    },
    onShowSizeChangePage (pageNo, pageSize) {
      this.pagination.pageSize = pageSize
      // 重新请求数据
      this.getList()
    }
  }
}
</script>

<style lang="less" scoped>
</style>
